package dk.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ReturnData.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import dk.beans.Dropdownconfig;
import dk.beans.loginconfig;
import dk.beans.switchconfig;
import dk.mapper.Dropdownconfigmapper;
import dk.mapper.loginconfigmapper;
import dk.mapper.switchconfigmapper;
import dk.services.TokenService;

@RestController
public class LoginConfigController {
	
@Autowired
loginconfigmapper loginconfigmapper;
@Autowired
TokenService tokenservice;
@Autowired
switchconfigmapper switchconfigmapper;
@Autowired
Dropdownconfigmapper dropdownconfigmapper;
@PostMapping("GetLoginConfigByAdminToken")
public ResponseData GetLoginConfig(String AdminToken) {
	System.out.println("GetLoginConfigByAdminToken开始");
	System.out.println(AdminToken);
	ResponseData data= new ResponseData();
	Map map = new HashMap();
	QueryWrapper<loginconfig> loginQueryWrapper = new QueryWrapper<loginconfig>();
	QueryWrapper<Dropdownconfig> dropdownWrapper = new QueryWrapper<Dropdownconfig>();
	QueryWrapper<switchconfig> swtichQueryWrapper = new QueryWrapper<switchconfig>();
	//根据AdminToken去查询出是否合法
	System.out.println("AdminToken"+AdminToken);
	Integer id = tokenservice.GetIdByAdmintoken(AdminToken);
	//int id =1;
	if(id!=0) {
		//如果合法则需要分别获取 下拉配置 登录配置 以及开关配置
		loginQueryWrapper.eq("id", id);
		swtichQueryWrapper.eq("id", id);
		dropdownWrapper.eq("id", id);
		
		//获取loginconfig
		loginconfig loginconfig=loginconfigmapper.selectOne(loginQueryWrapper);
		switchconfig switchconfig=switchconfigmapper.selectOne(swtichQueryWrapper);
		Dropdownconfig dropdownconfig = dropdownconfigmapper.selectOne(dropdownWrapper);
		if(loginconfig != null) {
			data.setCode(200);
			data.setMessage("配置信息拉取成功");
			map.put("LoginConfig", loginconfig);
			map.put("SwitchConfig", switchconfig);
			map.put("DropDownConfig",dropdownconfig);
			data.setData(map);
			
		}
		else {
			data.setCode(201);
			data.setMessage("未查询到配置信息,即将加载默认配置");
		}
		
	}
	else {
		data.setCode(201);
		data.setMessage("您没有进行注册或注册已经过期,即将加载默认配置");
		
	}
	
	return data;
}


}
